'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:PersonnelYcsqCtrl
 * @description
 * # PersonnelYcsqCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('PersonnelYcsqCtrl', function($scope, $location, $rootScope, DataService, openApi, Util, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
        $scope.showCarInfo = function() {
            var param = {}
            param.type = "车牌号码";
            DataService.getData(openApi.getKeyType, param).then(function(data) {
                $scope.carList = data
            })
        };
        $scope.timeUnitList = [{
            key: "天",
            value: "天"
        }, {
            key: "小时",
            value: "小时"
        }];
        $scope.submit = function(operationId) {

            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.useCar;
            options.param = angular.copy($scope.param, {});
            FormSubmit.submit(options,$scope);
        };
        $scope.validate = function() {
            if (!$scope.param.startUseDate) {
                Util.Toast("请选择用车起始日期");
                return;
            }
            if (!$scope.param.endUseDate) {
                Util.Toast("请选择用车结束日期");
                return;
            }
            if ($scope.param.relatedModuleName && $scope.param.relatedModuleName !== "无") {
                if (!$scope.param.moduleNo) {
                    Util.Toast("请选择模块编号");
                    return;
                }
            }
            if (!$scope.param.carInfo) {
                Util.Toast("请选择车牌号码");
                return;
            }
            if (!Util.checkDays($scope.param.costTime)) {
                Util.Toast("用车时长要为0.5的倍数");
                return;
            }
            if (!$scope.param.unit) {
                Util.Toast("请选择时间单位");
                return;
            }
            if (!$scope.param.startingLocation) {
                Util.Toast("请填写乘车地点");
                return;
            }
            if (!$scope.param.destination) {
                Util.Toast("请填写目的地");
                return;
            }
            if (!$scope.param.driver) {
                Util.Toast("请填写驾驶员信息");
                return;
            }
            if (!$scope.param.passenger) {
                Util.Toast("请填写乘客信息");
                return;
            }
            if (!$scope.param.remark) {
                Util.Toast("请填写用车事由");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }
        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData(id, function(data) {
                $scope.param = data;
            });
            $scope.showCarInfo()
        };
        // 初始化
        init();
    });